import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.apache.poi.hssf.eventusermodel.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class AccountingSBS extends JFrame
{
	//**** EXTRACTION DATA ***************************************START
	
	private String companyName;
	private String date;
	//Assets:
	//CA:
	private JTextField cashField;
	private JTextField acrField;
	private JTextField daField;
	private JTextField invField;
	private JTextField peField;
	private JTextField ocaField;
	//FA:
	private JTextField ltiField;
	private JTextField landField;
	private JTextField buiField;
	private JTextField adField;
	private JTextField ppeField;
	private JTextField ad1Field;
	//Liabilities
	//CL:
	private JTextField npField;
	private JTextField apField;
	private JTextField wpField;
	private JTextField ipField;
	private JTextField tpField;
	private JTextField acpField;
	private JTextField oclField;
	private JTextField ditField;
	private JTextField ollField;
	private JTextField ltdField;

	//Equity:
	private JTextField csField;
	private JTextField apcField;
	private JTextField reField;
	
	
	//**** EXTRACTION DATA *****************************************END
	private JPanel panelB;
	
	public AccountingSBS()
	{
		panelB = new JPanel();
		Dimension dimension1 = new Dimension(1000,1000);
		panelB.setSize(dimension1);
	}
	
	//FL:


	/**
	 * A measure of investor's expectations and current market conditions  
	 */
	
	public void peRatio() 
	{
		
		final JFrame frame = new JFrame("P/E Ratio");
        setSize(300, 300);
        
        // Set up the Share-Price field.
        Box priceLabelArea = Box.createHorizontalBox();   
        priceLabelArea.add(new JLabel("Share Price", JLabel.LEFT));
        priceLabelArea.add(Box.createGlue());
        final JTextField priceField = new JTextField(15);
        Box priceArea = Box.createVerticalBox(); 
        priceArea.add(priceLabelArea); 
        priceArea.add(priceField);
        
        // Set up the EPS field.
        Box epsLabelArea = Box.createHorizontalBox();   
        epsLabelArea.add(new JLabel("Earning Per Share", JLabel.LEFT));
        epsLabelArea.add(Box.createGlue());
        final JTextField epsField = new JTextField(15);
        Box epsArea = Box.createVerticalBox(); 
        epsArea.add(epsLabelArea); 
        epsArea.add(epsField);
        
        // Layout the entry-details fields in a panel.
        Box singleLineFields = Box.createVerticalBox();
        singleLineFields.add(priceArea);
        singleLineFields.add(epsArea);
        
        JPanel pane = new JPanel();
        pane.setLayout(new BorderLayout());
        pane.add(singleLineFields, BorderLayout.NORTH);
        
        // Set up the buttons.
        JPanel buttonArea = new JPanel();
        JButton compute = new JButton("Compute");
        JButton clear = new JButton("Clear");
         compute.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ev)
             {
            	 Double eps = 0.0;
            	 Double price = 0.0;
                 try {
                 // Computation
                 String str = priceField.getText();
                 price = Double.parseDouble(str);
                 String str1 = epsField.getText();
                 eps = Double.parseDouble(str1);
                 Double answer = price/eps;
                 String answer1 = (new Double(answer)).toString();
                 if (eps == 0.0 && price == 0.0) {
            		 JOptionPane.showMessageDialog(frame,"Please make sure you have typed a number greater than 0 in both the fields");
            	 } 
                 JOptionPane.showMessageDialog(frame,"Answer: " + answer1);
                 } catch (NumberFormatException e) {
                     JOptionPane.showMessageDialog(frame,"Please make sure you have entered a number in the space provided");
                    }
                }
            });
            clear.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ev)
                {
                    // Computation
                    priceField.setText("");
                    epsField.setText("");
                }
            });
            
        buttonArea.add(compute);
        buttonArea.add(clear);
        
        // Layout the details area above the button area.
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(pane, BorderLayout.CENTER);
        panel.add(buttonArea, BorderLayout.SOUTH);
        
        setContentPane(panel);
        pack();
        setVisible(true);
        }
	
	public void balanceSheet()
	{
		// Current ASSETS
        // Set up the Cash field.
   
        Box cashLabelArea = Box.createHorizontalBox();   
        cashLabelArea.add(new JLabel("Cash", JLabel.LEFT));
        cashLabelArea.add(Box.createGlue());
        cashField = new JTextField(10);
        Box cashArea = Box.createVerticalBox();
        cashArea.add(cashLabelArea); 
        cashArea.add(cashField);
       
        // Set up the A/C Recievable field.
        Box acrLabelArea = Box.createHorizontalBox();   
        acrLabelArea.add(new JLabel("Accounts Receivable", JLabel.LEFT));
        acrLabelArea.add(Box.createGlue());
        acrField = new JTextField(10);
        Box acrArea = Box.createVerticalBox(); 
        acrArea.add(acrLabelArea); 
        acrArea.add(acrField);
        
        // Set up the Doubtful Accounts field
        Box daLabelArea = Box.createHorizontalBox();   
        daLabelArea.add(new JLabel("[Doubtful Accounts]", JLabel.LEFT));
        daLabelArea.add(Box.createGlue());
        daField = new JTextField(10);
        Box daArea = Box.createVerticalBox(); 
        daArea.add(daLabelArea); 
        daArea.add(daField);
        
        // Set up the Inventory field
        Box invLabelArea = Box.createHorizontalBox();   
        invLabelArea.add(new JLabel("Inventory", JLabel.LEFT));
        invLabelArea.add(Box.createGlue());
        invField = new JTextField(10);
        Box invArea = Box.createVerticalBox(); 
        invArea.add(invLabelArea); 
        invArea.add(invField);
        
        // Set up the Prepaid Expenses field
        Box peLabelArea = Box.createHorizontalBox();   
        peLabelArea.add(new JLabel("Prepaid Expenses", JLabel.LEFT));
        peLabelArea.add(Box.createGlue());
        peField = new JTextField(10);
        Box peArea = Box.createVerticalBox(); 
        peArea.add(peLabelArea); 
        peArea.add(peField);
        
        // Set up the Other Current Assets field
        Box ocaLabelArea = Box.createHorizontalBox();   
        ocaLabelArea.add(new JLabel("Other Current Assets", JLabel.LEFT));
        ocaLabelArea.add(Box.createGlue());
        ocaField = new JTextField(10);
        Box ocaArea = Box.createVerticalBox(); 
        ocaArea.add(ocaLabelArea); 
        ocaArea.add(ocaField);        
                
        // Layout the entry-details fields in a panel.
        Box currentAssetLineFields = Box.createVerticalBox();
        currentAssetLineFields.setBorder(BorderFactory.createTitledBorder("Current Assets"));
        currentAssetLineFields.add(cashArea);
        currentAssetLineFields.add(acrArea);
        currentAssetLineFields.add(daArea);
        currentAssetLineFields.add(invArea);
        currentAssetLineFields.add(peArea);
        currentAssetLineFields.add(ocaArea);
        
//*********************************************************************
		// Fixed ASSETS

        // Set up the Long term Investments field.
        Box ltiLabelArea = Box.createHorizontalBox();   
        ltiLabelArea.add(new JLabel("Long term Investments", JLabel.LEFT));
        ltiLabelArea.add(Box.createGlue());
        ltiField = new JTextField(10);
        Box ltiArea = Box.createVerticalBox();
        ltiArea.add(ltiLabelArea); 
        ltiArea.add(ltiField);
       
        // Set up the Land field.
        Box landLabelArea = Box.createHorizontalBox();   
        landLabelArea.add(new JLabel("Land", JLabel.LEFT));
        landLabelArea.add(Box.createGlue());
        landField = new JTextField(10);
        Box landArea = Box.createVerticalBox(); 
        landArea.add(landLabelArea); 
        landArea.add(landField);
        
        // Set up the Bulidings field
        Box buiLabelArea = Box.createHorizontalBox();   
        buiLabelArea.add(new JLabel("Buildings", JLabel.LEFT));
        buiLabelArea.add(Box.createGlue());
        buiField = new JTextField(10);
        Box buiArea = Box.createVerticalBox(); 
        buiArea.add(buiLabelArea); 
        buiArea.add(buiField);
        
        // Set up the Accumulated Depreciation field for Buildings
        Box adLabelArea = Box.createHorizontalBox();   
        adLabelArea.add(new JLabel("[Accumulated Depreciation(Bulidings)]", JLabel.LEFT));
        adLabelArea.add(Box.createGlue());
        adField = new JTextField(10);
        Box adArea = Box.createVerticalBox(); 
        adArea.add(adLabelArea); 
        adArea.add(adField);
        
        // Set up the Property, Plant and Equipment field
        Box ppeLabelArea = Box.createHorizontalBox();   
        ppeLabelArea.add(new JLabel("Property,Plant and Equipment", JLabel.LEFT));
        ppeLabelArea.add(Box.createGlue());
        ppeField = new JTextField(10);
        Box ppeArea = Box.createVerticalBox(); 
        ppeArea.add(ppeLabelArea); 
        ppeArea.add(ppeField);
        
        // Set up the Accumulated Depreciation field for Property, Plant and Equipment
        Box ad1LabelArea = Box.createHorizontalBox();   
        ad1LabelArea.add(new JLabel("[Accumulated Depreciation(Property, Plant and Equipment)]", JLabel.LEFT));
        ad1LabelArea.add(Box.createGlue());
        ad1Field = new JTextField(10);
        Box ad1Area = Box.createVerticalBox(); 
        ad1Area.add(ad1LabelArea); 
        ad1Area.add(ad1Field);
        
        // Layout the entry-details fields in a panel.
        Box fixedassetLineFields = Box.createVerticalBox();
        fixedassetLineFields.setBorder(BorderFactory.createTitledBorder("Fixed Assets"));
        fixedassetLineFields.add(ltiArea);
        fixedassetLineFields.add(landArea);
        fixedassetLineFields.add(buiArea);
        fixedassetLineFields.add(adArea);
        fixedassetLineFields.add(ppeArea);
        fixedassetLineFields.add(ad1Area);        
//**********************************************************************        
        JPanel assetArea = new JPanel(new GridLayout(2, 1));
        assetArea.setBorder(BorderFactory.createTitledBorder("Assets"));
        assetArea.setLayout(new BorderLayout());
        assetArea.add(currentAssetLineFields, BorderLayout.NORTH);
        assetArea.add(fixedassetLineFields, BorderLayout.SOUTH);
        
        // Liabilities
        // Set up the Notes Payable field.
        Box npLabelArea = Box.createHorizontalBox();   
        npLabelArea.add(new JLabel("Notes Payable", JLabel.LEFT));
        npLabelArea.add(Box.createGlue());
        npField = new JTextField(10);
        Box npArea = Box.createVerticalBox(); 
        npArea.add(npLabelArea); 
        npArea.add(npField);
        
        // Set up the A/C Payable field.
        Box apLabelArea = Box.createHorizontalBox();   
        apLabelArea.add(new JLabel("Accounts Payable", JLabel.LEFT));
        apLabelArea.add(Box.createGlue());
        apField = new JTextField(10);
        Box apArea = Box.createVerticalBox(); 
        apArea.add(apLabelArea); 
        apArea.add(apField);
        
        // Set up the Wages Payable field.
        Box wpLabelArea = Box.createHorizontalBox();   
        wpLabelArea.add(new JLabel("Wages Payable", JLabel.LEFT));
        wpLabelArea.add(Box.createGlue());
        wpField = new JTextField(10);
        Box wpArea = Box.createVerticalBox(); 
        wpArea.add(wpLabelArea); 
        wpArea.add(wpField);
        
        // Set up the Interest Payable field.
        Box ipLabelArea = Box.createHorizontalBox();   
        ipLabelArea.add(new JLabel("Interest Payable", JLabel.LEFT));
        ipLabelArea.add(Box.createGlue());
        ipField = new JTextField(10);
        Box ipArea = Box.createVerticalBox(); 
        ipArea.add(ipLabelArea); 
        ipArea.add(ipField);
        
        // Set up the Taxes Payable field.
        Box tpLabelArea = Box.createHorizontalBox();   
        tpLabelArea.add(new JLabel("Taxes Payable", JLabel.LEFT));
        tpLabelArea.add(Box.createGlue());
        tpField = new JTextField(10);
        Box tpArea = Box.createVerticalBox(); 
        tpArea.add(tpLabelArea); 
        tpArea.add(tpField);

        // Set up the Accrued payroll field        
        Box acpLabelArea = Box.createHorizontalBox();   
        acpLabelArea.add(new JLabel("Accrued Payroll", JLabel.LEFT));
        acpLabelArea.add(Box.createGlue());
        acpField = new JTextField(10);
        Box acpArea = Box.createVerticalBox(); 
        acpArea.add(acpLabelArea); 
        acpArea.add(acpField);
        
        // Set up the "Other Current Liabilities" field.
        Box oclLabelArea = Box.createHorizontalBox();   
        oclLabelArea.add(new JLabel("Other Current Liabilities", JLabel.LEFT));
        oclLabelArea.add(Box.createGlue());
        oclField = new JTextField(10);
        Box oclArea = Box.createVerticalBox(); 
        oclArea.add(oclLabelArea); 
        oclArea.add(oclField);
        
        // Layout the entry-details fields in a panel.
        Box clFields = Box.createVerticalBox();
        clFields.setBorder(BorderFactory.createTitledBorder("Current Liabilities"));
        clFields.add(npArea);
        clFields.add(apArea);
        clFields.add(wpArea);
        clFields.add(ipArea);
        clFields.add(tpArea);
        clFields.add(acpArea);
        clFields.add(oclArea);
        
//**********************************************************************        
        // Set up the Long Term Debt field.
        Box ltdLabelArea = Box.createHorizontalBox();   
        ltdLabelArea.add(new JLabel("Long Term Debt", JLabel.LEFT));
        ltdLabelArea.add(Box.createGlue());
        ltdField = new JTextField(10);
        Box ltdArea = Box.createVerticalBox();
        ltdArea.add(ltdLabelArea); 
        ltdArea.add(ltdField);
        
        // Set up the Deferred Income Taxes field.
        Box ditLabelArea = Box.createHorizontalBox();   
        ditLabelArea.add(new JLabel("Deferred Income Taxes", JLabel.LEFT));
        ditLabelArea.add(Box.createGlue());
        ditField = new JTextField(10);
        Box ditArea = Box.createVerticalBox(); 
        ditArea.add(ditLabelArea); 
        ditArea.add(ditField);
        
        // Set up the Other Long Term Liabilities field.
        Box ollLabelArea = Box.createHorizontalBox();   
        ollLabelArea.add(new JLabel("Other Long Term Liabilities", JLabel.LEFT));
        ollLabelArea.add(Box.createGlue());
        ollField = new JTextField(10);
        Box ollArea = Box.createVerticalBox(); 
        ollArea.add(ollLabelArea); 
        ollArea.add(ollField);
        
        // Layout the entry-details fields in a panel.
        Box ltlFields = Box.createVerticalBox();
        ltlFields.setBorder(BorderFactory.createTitledBorder("Long-Term Liabilities"));
        ltlFields.add(ltdArea);
        ltlFields.add(ditArea);
        ltlFields.add(ollArea);
//*********************************************************************        
        
        JPanel liabilityArea = new JPanel(new GridLayout(2, 1));
        liabilityArea.setBorder(BorderFactory.createTitledBorder("Liabilities"));
        liabilityArea.setLayout(new BorderLayout());
        liabilityArea.add(clFields, BorderLayout.NORTH);
        liabilityArea.add(ltlFields, BorderLayout.SOUTH);
        
        // Equity
        // Set up the Capital stock field.
        Box csLabelArea = Box.createHorizontalBox();   
        csLabelArea.add(new JLabel("Capital Stock", JLabel.LEFT));
        csLabelArea.add(Box.createGlue());
        csField = new JTextField(15);
        Box csArea = Box.createVerticalBox(); 
        csArea.add(csLabelArea); 
        csArea.add(csField);
       
        // Set up the Additional Paid in Capital field.
        Box apcLabelArea = Box.createHorizontalBox();   
        apcLabelArea.add(new JLabel("Additional Paid in Capital", JLabel.LEFT));
        apcLabelArea.add(Box.createGlue());
        apcField = new JTextField(15);
        Box apcArea = Box.createVerticalBox(); 
        apcArea.add(apcLabelArea); 
        apcArea.add(apcField);
        
        // Set up the Retained earnings field.
        Box reLabelArea = Box.createHorizontalBox();   
        reLabelArea.add(new JLabel("Retained Earnings", JLabel.LEFT));
        reLabelArea.add(Box.createGlue());
        reField = new JTextField(15);
        Box reArea = Box.createVerticalBox(); 
        reArea.add(reLabelArea); 
        reArea.add(reField);
        
        // Layout the entry-details fields in a panel.
        Box equityLineFields = Box.createVerticalBox();
        equityLineFields.add(csArea);
        equityLineFields.add(apcArea);
        equityLineFields.add(reArea);
       
        JPanel equityArea = new JPanel(new GridLayout(2, 1));
        equityArea.setSize(new Dimension(20,20));
        equityArea.setBorder(BorderFactory.createTitledBorder("Shareholder's Equity"));
        equityArea.setLayout(new BorderLayout());
        equityArea.add(equityLineFields, BorderLayout.NORTH);
        
        JPanel buttonArea1 = new JPanel();
        
        JButton saveAs = new JButton("Save");
        saveAs.setMnemonic(KeyEvent.VK_M);
        saveAs.setToolTipText("Save in a file called 1trialworkbook.xls");
        
        JButton load = new JButton("Load");
        load.setMnemonic(KeyEvent.VK_L);
        load.setToolTipText("");
        
        JButton clear = new JButton("Clear");
        load.setMnemonic(KeyEvent.VK_L);
        load.setToolTipText("Achtung!!! It will clear everything in" +
        		"the box as well as the values you stored in the" +
        		"excel sheet ");

         saveAs.addActionListener(new ActionListener(){

			@SuppressWarnings("deprecation")
			public void actionPerformed(ActionEvent ev)
             {
            	//***
            	 try {
        		 Workbook wb = new HSSFWorkbook();
        		 HSSFSheet sheet = (HSSFSheet) wb.createSheet("Sheet1");
        		 
        		 //Balance Sheet Headers
        		 HSSFRow balanceSheetheaderRow = sheet.createRow((short)0);
        		 HSSFCell balanceSheetheaderCell = balanceSheetheaderRow.createCell((short)4);
        		 balanceSheetheaderCell.setCellValue("Balance Sheet");
        		 HSSFRow balanceSheetheaderRow1 = sheet.createRow((short) 1);
        		 HSSFCell balanceSheetheaderCell1 = balanceSheetheaderRow1.createCell((short)4);
        		 balanceSheetheaderCell1.setCellValue(companyName);
        		 HSSFRow balanceSheetheaderRow2 = sheet.createRow((short) 2);
        		 HSSFCell balanceSheetheaderCell2 = balanceSheetheaderRow2.createCell((short)4);
        		 balanceSheetheaderCell2.setCellValue(date);
        		 
           		 // Setting fucking fonts.*******************
           		 HSSFCellStyle cell1Style = (HSSFCellStyle) wb.createCellStyle();
          		 
           		 HSSFFont fontc = (HSSFFont) wb.createFont();
                 fontc.setColor(HSSFFont.COLOR_RED); 
           		 cell1Style.setFont(fontc);
        		 
        		 //Set the fields for the Asset side
        		 // Assets
        		 HSSFRow row = sheet.createRow((short)4);
        		 HSSFCell cell = row.createCell((short) 0);
        		 HSSFCell cell16 = row.createCell((short) 8);
        		 cell.setCellValue("Assets");
        		 cell.setCellStyle(cell1Style);
//        		 HSSFCellStyle cellStyle = (HSSFCellStyle) wb.createCellStyle();
//           		 cellStyle.setFillForegroundColor(HSSFColor.BLUE_GREY.index);
//           		 cell.setCellStyle(cellStyle);
        		 
           		 //**** Fonts, Foregrounds, Backgrounds Extraction
        		 //cellStyle.setFillForegroundColor(HSSFColor.DARK_RED.index);
                 
        		 // ********************
        		 
        		 cell16.setCellValue("Liabilities");
        		 cell16.setCellStyle(cell1Style);
        		 
				 HSSFRow row1 = sheet.createRow((short)5);
        		 HSSFCell cell1 = row1.createCell((short) 0);
        		 cell1.setCellValue("Current Assets");
           		 
                 cell1.setCellStyle(cell1Style);
           		 //******************************************
        		 
        		 HSSFRow row2 = sheet.createRow((short)6);
        		 HSSFCell cell2 = row2.createCell((short) 0);
        		 HSSFCell cell2a = row2.createCell((short) 4);
        		 cell2.setCellValue("Cash");
        		 cell2a.setCellValue(Integer.parseInt(cashField.getText().trim()));
        		
        		 HSSFRow row3 = sheet.createRow((short)7);
           		 HSSFCell cell3 = row3.createCell((short) 0);
           		 HSSFCell cell3a = row3.createCell((short)4);
           		 cell3.setCellValue("Accounts Receivable");
           		 cell3a.setCellValue(Integer.parseInt(acrField.getText().trim()));
					
           		 HSSFRow row4 = sheet.createRow((short)8);
           		 HSSFCell cell4 = row4.createCell((short) 0);
           		 HSSFCell cell4a = row4.createCell((short)4);
           		 cell4.setCellValue("(Doubtful Accounts)");
           		 cell4a.setCellValue(Integer.parseInt(daField.getText().trim()));
					
           		 HSSFRow row5 = sheet.createRow((short)9);
           		 HSSFCell cell5 = row5.createCell((short) 0);
           		 HSSFCell cell5a = row5.createCell((short)4);
           		 cell5.setCellValue("Inventory");
           		 cell5a.setCellValue(Integer.parseInt(invField.getText().trim()));
					
           		 HSSFRow row6 = sheet.createRow((short)10);
           		 HSSFCell cell6 = row6.createCell((short) 0);
           		 HSSFCell cell6a = row6.createCell((short)4);
           		 cell6.setCellValue("Prepaid Expenses");
           		 cell6a.setCellValue(Integer.parseInt(peField.getText().trim()));
					
           		 HSSFRow row7 = sheet.createRow((short)11);
           		 HSSFCell cell7 = row7.createCell((short) 0);
           		 HSSFCell cell7a = row7.createCell((short)4);
           		 cell7.setCellValue("Other current assets");
				 cell7a.setCellValue(Integer.parseInt(ocaField.getText().trim()));	
           		 
				 HSSFRow row8 = sheet.createRow((short)12);
				 HSSFCell cell8 = row8.createCell((short) 0);
           		 cell8.setCellValue("Fixed Assets");
           		 
           		 // Setting fonts.*******************
//           		 HSSFCellStyle cell8Style = (HSSFCellStyle) wb.createCellStyle();
//          		 
//           		 HSSFFont fontb = (HSSFFont) wb.createFont();
//                 fontb.setColor(HSSFFont.COLOR_RED); 
//           		 cell8Style.setFont(fontb);
//           		 
                 cell8.setCellStyle(cell1Style);
           		 //******************************************
				
           		 HSSFRow row9 = sheet.createRow((short)13);
				 HSSFCell cell9 = row9.createCell((short) 0);
				 HSSFCell cell9a = row9.createCell((short) 4);
				 cell9.setCellValue("Long-term Investment");
				 cell9a.setCellValue(Integer.parseInt(ltiField.getText().trim()));
				 
				 HSSFRow row10 = sheet.createRow((short)14);
				 HSSFCell cell10 = row10.createCell((short) 0);
				 HSSFCell cell10a = row10.createCell((short) 4);
				 cell10.setCellValue("Land");
				 cell10a.setCellValue(Integer.parseInt(landField.getText().trim()));
				 
				 HSSFRow row11 = sheet.createRow((short)15);
				 HSSFCell cell11 = row11.createCell((short) 0);
				 HSSFCell cell11a = row11.createCell((short) 4);
				 cell11.setCellValue("Buildings");
				 cell11a.setCellValue(Integer.parseInt(buiField.getText().trim()));
				
				 HSSFRow row12 = sheet.createRow((short)16);
				 HSSFCell cell12 = row12.createCell((short) 0);
				 HSSFCell cell12a = row12.createCell((short) 4);
				 cell12.setCellValue("Accumulated Depreciation, Buildings");
				 cell12a.setCellValue(Integer.parseInt(adField.getText().trim()));
				 
				 HSSFRow row13 = sheet.createRow((short)17);
				 HSSFCell cell13 = row13.createCell((short) 0);
				 HSSFCell cell13a = row13.createCell((short) 4);
			     cell13.setCellValue("Property, Plant and Equipment");
				 cell13a.setCellValue(Integer.parseInt(ppeField.getText().trim()));
			     
				 HSSFRow row14 = sheet.createRow((short)18);
				 HSSFCell cell14a = row14.createCell((short) 4);
				 HSSFCell cell14 = row14.createCell((short) 0);
				 cell14.setCellValue("Accumulated Depreciation, PPE");
				 cell14a.setCellValue(Integer.parseInt(ad1Field.getText().trim()));
				 
				 HSSFRow row15 = sheet.createRow((short)22);
				 HSSFCell cell15 = row15.createCell((short) 0);
				 HSSFCell cell15a = row15.createCell((short)4);
				 cell15.setCellValue("Total Assets");
				 cell15a.setCellValue(
				 Integer.parseInt(ppeField.getText().trim())
				 - Integer.parseInt(ad1Field.getText().trim())
				 - Integer.parseInt(adField.getText().trim())
				 + Integer.parseInt(buiField.getText().trim())
				 + Integer.parseInt(landField.getText().trim())
				 + Integer.parseInt(ltiField.getText().trim())
				 + Integer.parseInt(ocaField.getText().trim())
				 + Integer.parseInt(peField.getText().trim())
				 + Integer.parseInt(invField.getText().trim())
				 - Integer.parseInt(daField.getText().trim())
				 + Integer.parseInt(acrField.getText().trim())
				 + Integer.parseInt(cashField.getText().trim())
				 );
				 
           		 // Setting fonts.*******************
           		 HSSFCellStyle cell15Style = (HSSFCellStyle) wb.createCellStyle();
          		 
           		 HSSFFont fontd = (HSSFFont) wb.createFont();
                 fontd.setColor(HSSFFont.COLOR_RED); 
           		 cell15Style.setFont(fontd);
           		 
                 cell15.setCellStyle(cell15Style);
           		 //******************************************
				 
				// Liabilities
        		         		 
				 HSSFCell cell17 = row1.createCell((short) 8);
        		 cell17.setCellValue("Current Liabilities");
        		 
           		 // Setting fonts.*******************
           		 HSSFCellStyle cell17Style = (HSSFCellStyle) wb.createCellStyle();
          		 
           		 HSSFFont fonta = (HSSFFont) wb.createFont();
                 fonta.setColor(HSSFFont.COLOR_RED); 
           		 cell17Style.setFont(fonta);
           		 
                 cell17.setCellStyle(cell17Style);
           		 //******************************************
				
        		 HSSFCell cell18 = row2.createCell((short) 8);
        		 HSSFCell cell18a = row2.createCell((short) 12);
        		 cell18.setCellValue("Notes Payable");
        		 cell18a.setCellValue(Integer.parseInt(npField.getText().trim()));
        		
        		 HSSFCell cell19 = row3.createCell((short) 8);
        		 HSSFCell cell19a = row3.createCell((short)12);
           		 cell19.setCellValue("Accounts Payable");
           		 cell19a.setCellValue(Integer.parseInt(apField.getText().trim()));
					
           		 HSSFCell cell20 = row4.createCell((short) 8);
           		 HSSFCell cell20a = row4.createCell((short)12);
           		 cell20.setCellValue("Wages Payable");
           		 cell20a.setCellValue(Integer.parseInt(wpField.getText().trim()));
					
           		 HSSFCell cell21 = row5.createCell((short) 8);
           		 HSSFCell cell21a = row5.createCell((short)12);
           		 cell21.setCellValue("Interest Payable");
           		 cell21a.setCellValue(Integer.parseInt(ipField.getText().trim()));
					
           		 HSSFCell cell22 = row6.createCell((short) 8);
           		 HSSFCell cell22a = row6.createCell((short)12);
           		 cell22.setCellValue("Taxes Payable");
           		 cell22a.setCellValue(Integer.parseInt(tpField.getText().trim()));
           		 
           		 HSSFCell cell23 = row7.createCell((short) 8);
           		 HSSFCell cell23a = row7.createCell((short)12);
           		 cell23.setCellValue("Accrued Payroll");
           		 cell23a.setCellValue(Integer.parseInt(acpField.getText().trim()));
           		 
           		 HSSFCell cell24 = row8.createCell((short) 8);
           		 HSSFCell cell24a = row8.createCell((short)12);
           		 cell24.setCellValue("Other Current Liabilities");
           		 cell24a.setCellValue(Integer.parseInt(oclField.getText().trim()));
           		 
           		 HSSFCell cell25 = row9.createCell((short) 8);
           		 cell25.setCellValue("Long-term Liabilities");
           		 
           		 // Setting fucking fonts.*******************
           		 cell25.setCellStyle(cell17Style);
           		 //******************************************
                 
           		 HSSFCell cell26 = row10.createCell((short) 8);
           		 HSSFCell cell26a = row10.createCell((short)12);
           		 cell26.setCellValue("Long-term Debt");
				 cell26a.setCellValue(Integer.parseInt(ocaField.getText().trim()));	
           		 
				 HSSFCell cell27 = row11.createCell((short) 8);
           		 HSSFCell cell27a = row11.createCell((short)12);
           		 cell27.setCellValue("Deffered Income Taxes");
				 cell27a.setCellValue(Integer.parseInt(ditField.getText().trim()));	

				 HSSFCell cell28 = row12.createCell((short) 8);
           		 HSSFCell cell28a = row12.createCell((short)12);
           		 cell28.setCellValue("Other Long-term Liabilities");
				 cell28a.setCellValue(Integer.parseInt(ocaField.getText().trim()));	
				 
				 HSSFCell cell29 = row14.createCell((short) 8);
           		 cell29.setCellValue("Equity");
           		 cell29.setCellStyle(cell17Style);			     
           		 
           		 HSSFRow row30 = sheet.createRow((short)19);
           		 HSSFCell cell30 = row30.createCell((short) 8);
				 HSSFCell cell30a = row30.createCell((short) 12);
				 cell30.setCellValue("Capital Stock");
				 cell30a.setCellValue(Integer.parseInt(csField.getText().trim()));
				 
				 HSSFRow row31 = sheet.createRow((short)20);
				 HSSFCell cell31 = row31.createCell((short) 8);
				 HSSFCell cell31a = row31.createCell((short) 12);
				 cell31.setCellValue("Additional Paid in Capital");
				 cell31a.setCellValue(Integer.parseInt(apcField.getText().trim()));
				 
				 HSSFRow row32 = sheet.createRow((short)21);
				 HSSFCell cell32 = row32.createCell((short) 8);
				 HSSFCell cell32a = row32.createCell((short) 12);
				 cell32.setCellValue("Retained Earnings");
				 cell32a.setCellValue(Integer.parseInt(reField.getText().trim()));
				 
				 HSSFCell cell33 = row15.createCell((short) 8);
				 HSSFCell cell33a = row15.createCell((short)12);
				 cell33.setCellValue("Total Liabilities and Equity");
				 cell33a.setCellValue(
				 Integer.parseInt(npField.getText().trim())
				 + Integer.parseInt(apField.getText().trim())
				 + Integer.parseInt(wpField.getText().trim())
				 + Integer.parseInt(ipField.getText().trim())
				 + Integer.parseInt(tpField.getText().trim())
				 + Integer.parseInt(acpField.getText().trim())
				 + Integer.parseInt(oclField.getText().trim())
				 + Integer.parseInt(ltdField.getText().trim())
				 + Integer.parseInt(ditField.getText().trim())
				 + Integer.parseInt(ollField.getText().trim())
				 + Integer.parseInt(csField.getText().trim())
				 + Integer.parseInt(apcField.getText().trim())
				 + Integer.parseInt(reField.getText().trim())
				 );
				 
				 cell33.setCellStyle(cell17Style);
                 
				 if ( cell33a.getNumericCellValue() == cell15a.getNumericCellValue())
				 {
					 HSSFRow row25 = sheet.createRow(24);
					 HSSFCell cell25a = row25.createCell(4);
					 cell25a.setCellValue("The Assets side is equal " +
					 		"to the Liability and Equity side.");
				 }
				 else {					 					 
					 HSSFRow row25 = sheet.createRow(24);
					 HSSFCell cell25a = row25.createCell(4);
					 cell25a.setCellValue("The Assets side and the " +
					 		"Liability and Equity side are unbalanced.");
					// Setting fonts.*******************
	           		 HSSFCellStyle cell25Style = (HSSFCellStyle) wb.createCellStyle();
	          		 
	           		 HSSFFont fontg = (HSSFFont) wb.createFont();
	                 fontg.setColor(HSSFFont.COLOR_RED); 
	           		 cell25Style.setFont(fontg);
	           		 
	                 cell25a.setCellStyle(cell25Style);
	           		 //******************************************
				 }
				 
				 
				 String name = companyName.trim() + "_" + date.trim() + "_" + "BalanceSheet";

				 FileOutputStream fileOut = new FileOutputStream
          		 (name + ".xls");

           		// get a reference to the worksheet           		
           		 wb.write(fileOut);
           		 fileOut.close();
           		 
            }
            	 catch (Exception nfe)
            	 {
            		 
            	 }
             }
            });
            load.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ev)
                {
                //*** POI-Time	
   				 //readCell(cell33a);
				 //readCell(cell33);	
                 
                }
            });
            clear.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ev)
                {
                	
                 
                }
            });
            
        buttonArea1.add(saveAs);
        buttonArea1.add(load);
        buttonArea1.add(clear);
        
        buttonArea1.add(saveAs);
        buttonArea1.add(load);
        buttonArea1.add(clear);                         

        // Layout the Liabilities and Equity details.
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(1, 1));
        panel.add(liabilityArea, BorderLayout.NORTH);
        panel.add(equityArea, BorderLayout.SOUTH);            
        
        // Layout the Button-area, Assets, Liabilities and Equity details.
        
        panelB.setLayout(new BorderLayout());
        panelB.add(assetArea, BorderLayout.WEST);
        panelB.add(panel, BorderLayout.EAST);
        panelB.add(buttonArea1,BorderLayout.SOUTH);
        
        setContentPane(panelB);
        setResizable(false);
        pack();
        setVisible(true);
    }
	
	public void readCell(Cell cell)
	{
		switch(cell.getCellType()) {
	      case Cell.CELL_TYPE_STRING:
	        System.out.println(cell.getRichStringCellValue().getString());
	        break;
	      case Cell.CELL_TYPE_NUMERIC:
	          System.out.println(cell.getNumericCellValue());
	        break;
	      case Cell.CELL_TYPE_BOOLEAN:
	        System.out.println(cell.getBooleanCellValue());
	        break;
	      case Cell.CELL_TYPE_FORMULA:
	        System.out.println(cell.getCellFormula());
	        break;
	      default:
	        System.out.println();
			}
	}
	
	public void firstEntry()
	{
		final JFrame frame = new JFrame("Company Entry");
		// Set up the Company Name field.
        Box priceLabelArea = Box.createHorizontalBox();   
        priceLabelArea.add(new JLabel("Company Name", JLabel.LEFT));
        priceLabelArea.add(Box.createGlue());
        final JTextField companyField = new JTextField(15);
        Box priceArea = Box.createVerticalBox(); 
        priceArea.add(priceLabelArea); 
        priceArea.add(companyField);
        
        // Set up the Date field.
        Box epsLabelArea = Box.createHorizontalBox();   
        epsLabelArea.add(new JLabel("Date", JLabel.LEFT));
        epsLabelArea.add(Box.createGlue());
        final JTextField dateField = new JTextField(15);
        Box epsArea = Box.createVerticalBox(); 
        epsArea.add(epsLabelArea); 
        epsArea.add(dateField);
        
        // Layout the entry-details fields in a panel.
        Box singleLineFields1 = Box.createVerticalBox();
        singleLineFields1.add(priceArea);
        singleLineFields1.add(epsArea);
        
        JPanel pane = new JPanel();
        pane.setLayout(new BorderLayout());
        pane.add(singleLineFields1, BorderLayout.NORTH);
        
        // GET INFO

        
        // Set up the buttons.
        JPanel buttonArea = new JPanel();
        JButton compute = new JButton("Compute");
        JButton clear = new JButton("Clear");
         compute.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ev)
             {
            	 companyName = companyField.getText();
                 date = dateField.getText();
                 JLabel companyNameLabel = new JLabel(companyName, JLabel.CENTER);
                 JLabel dateLabel = new JLabel(date, JLabel.CENTER);
                 JPanel infoPanel = new JPanel(new BorderLayout(2, 1));
            	 infoPanel.add(companyNameLabel, BorderLayout.NORTH);
            	 infoPanel.add(dateLabel, BorderLayout.SOUTH);
                 
            	 JPanel panel5 = new JPanel();
                 panel5.setLayout(new BorderLayout(1, 1));
                 panel5.add(infoPanel, BorderLayout.NORTH);
                 balanceSheet();
                 panel5.add(panelB, BorderLayout.SOUTH);
                 
                 setContentPane(panel5);
                 pack();
                 setVisible(true);
                }
            });
            clear.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ev)
                {
                    // Computation
                    companyField.setText("");
                    dateField.setText("");
                }
            });
            
        buttonArea.add(compute);
        buttonArea.add(clear);
        
        // Layout the details area above the button area.
        JPanel panel2 = new JPanel();
        panel2.setLayout(new BorderLayout());
        panel2.add(pane, BorderLayout.CENTER);
        panel2.add(buttonArea, BorderLayout.SOUTH);
        setContentPane(panel2);
        pack();
        setVisible(true);		
	}
	
    private void balanceSheetSave()
    {
    	
    }
    
    private void balanceSheetLoad()
    {
    	
    }
	
}
